//
//  SPRecentMessageCell.m
//  Sport
//
//  Created by Cass on 2018/4/6.
//  Copyright © 2018年 Cass. All rights reserved.
//

#import "SPRecentMessageCell.h"
#import "SPRecentMessage.h"
@interface SPRecentMessageCell()
@property (nonatomic, weak) UIImageView *headImg;
@property (nonatomic, weak) UILabel *friendNameLabel;
@property (nonatomic, weak) UILabel *messageLabel;
@property (nonatomic, weak) UILabel *timeLabel;
@end
@implementation SPRecentMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];

}

- (void)setRecentmessage:(SPRecentMessage *)recentmessage{
    _recentmessage = recentmessage;
    //设置头像
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 40, 40)];
    imgView.image = [UIImage imageNamed:recentmessage.headImage];
    imgView.layer.cornerRadius = imgView.bounds.size.width / 2;
    imgView.layer.masksToBounds = YES;
    [self.contentView addSubview:imgView];
    self.headImg = imgView;
    //设置好友昵称label
    UILabel *friendLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imgView.frame) + 15, 5, 100, 21)];
    friendLabel.font = [UIFont systemFontOfSize:15.0f];
    friendLabel.text = recentmessage.friendName;
    [self.contentView addSubview:friendLabel];
    self.friendNameLabel = friendLabel;
    //设置消息label
    UILabel *msgLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imgView.frame) + 15, CGRectGetMaxY(friendLabel.frame), 150, 21)];
    msgLabel.font = [UIFont systemFontOfSize:13.0f];
    msgLabel.text = recentmessage.message;
    msgLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:msgLabel];
    self.messageLabel = msgLabel;
    //设置时间label
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.font = [UIFont systemFontOfSize:15.0f];
    timeLabel.text = recentmessage.time;
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_equalTo(self.contentView).offset(-5);
        make.height.mas_equalTo(21);
        make.width.mas_equalTo(50);
    }];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _setup];
    }
    return self;
}
- (void)_setup{
    self.backgroundColor = [UIColor whiteColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
}
+ (instancetype)recentMessageCellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"cell";
    SPRecentMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
    }
    return cell;
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
